package com.hospital.payment.module.message;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
public class OrderTimeoutProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Value("${topic.order-timeout}")
    private String TOPIC;
    @Value("${message.delay-level}")
    private Integer DELAY_LEVEL;
    @Value("${message.timeout}")
    private Long TIMEOUT;

    /**
     * 延迟发送订单超时消息
     */
    public SendResult sendOrderTimeoutMessage(OrderTimeoutMessage orderTimeoutMessage) {
        return rocketMQTemplate.syncSend(TOPIC, MessageBuilder.withPayload(orderTimeoutMessage).build(),TIMEOUT ,DELAY_LEVEL);
    }
}
